﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class MethodBodyElement : SyntaxTreeElement
    {
        private List<ISyntaxTreeElement> declarations;
        private StatementElement statement;

        public List<ISyntaxTreeElement> Declarations { get { return declarations; } set { declarations = value; } }
        public StatementElement Statement { get { return statement; } set { statement = value; } }

        public MethodBodyElement(TokenInfo StartInfo, List<ISyntaxTreeElement> Declarations, StatementElement Statement, List<TokenInfo> Comments)
            : base(StartInfo, Comments)
        {
            declarations = Declarations;
            statement = Statement;
        }

        public override string ToString()
        {
            return string.Format("{0}{1}", ((declarations != null) && (declarations.Count > 0)) ? string.Format("{0}\r\n", declarations.Join("\r\n\r\n")) : string.Empty, statement);
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (declarations != null)
                foreach (ISyntaxTreeElement declaration in declarations)
                    yield return declaration;
            yield return statement;
        }
    }
}
